<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="test1"></div>
  <div id="test2"></div>
  <div id="test3"></div>
  <!-- 引入react核心库 -->
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <!-- 用于支持react操作DOM -->
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <!-- 用于将jsx转为js -->
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <!-- 用于全局引入PropTypes，对标签属性进行限制  -->
  <script src="https://unpkg.com/prop-types@15.6/prop-types.js"></script>
  
  <script type="text/babel">
    class Person extends React.Component{
      //限制传入的props标签属性
      static propTypes={
        name:PropTypes.string.isRequired,//限制name为必须传，且为string类型
        sex:PropTypes.string,
        age:PropTypes.number,
        speak:PropTypes.func,//限制speak类型为函数
      }
      //设置默认的props标签属性
      static defaultProps={
        sex:'男',
        age:18
      }
      render(){
        // console.log(this);
        //props是只读的，不能修改
        const {name,age,sex}=this.props;
        return(
          <ul>
            <li>姓名：{name}</li>
            <li>性别：{sex}</li>
            <li>年龄：{age+1}</li>
          </ul>
        )
      }
    }
    
    //组件外部传值
    ReactDOM.render(<Person name='Tom' age={18} speak={speak}/>,document.getElementById('test1'))
    ReactDOM.render(<Person name='curry' sex='女'/>,document.getElementById('test2'))
    let person={name:'jack',age:29,sex:'女'}
    ReactDOM.render(<Person {...person}/>,document.getElementById('test3'))

    function speak(){
      console.log('hello world');
    }
  </script>
</body>
</html>